package v3.chapter3.firstNotify;

public class Run2 {

	private String lock = new String("");
	private boolean isFirstRunB=false;
	private Runnable runnableA = new Runnable() {
		@Override
		public void run() {
			try {
				synchronized (lock) {
					while(isFirstRunB==false) {
						System.out.println("begin wait");
						lock.wait();
						System.out.println("end wait");
					}
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	};

	private Runnable runnableB = new Runnable() {
		@Override
		public void run() {

			synchronized (lock) {
				System.out.println("begin notify");
				lock.notify();
				System.out.println("end notify");
				isFirstRunB=true;
			}
		}
	};
	
	public static void main(String[] args) throws InterruptedException {
		Run2 myrun=new Run2();
		Thread b=new Thread(myrun.runnableB);
		b.start();
		Thread.sleep(1000);  
		Thread a=new Thread(myrun.runnableA);
		a.start();
	}

}
